local skynet
local packdeal
local send_package
local unpack_package

local NetCmd = require "common/NetCmd"

if IS_SERVER_MODULE then

	skynet = require "skynet"
	packdeal = require "packdeal"
	send_package = packdeal.send_package
	unpack_package = packdeal.unpack_package

end

local itemSchema = {
    id      = { typ = "number", default = 0, sync = true },
    num     = { typ = "number", default = 1, sync = true },
    timestamp   = { typ = "number", default = 0, sync = true },
}

item_t = class("item_t")
function item_t:ctor()
    set_schema({
        obj = self,
        schema = itemSchema,
    })
end	

local userSchema = {
    uid     		= { typ = "number", default = 0, sync = true },     -- uid 
    name    		= { typ = "string", default = "", sync = true },
	head    		= { typ = "string", default = "", sync = true },
	sex	    		= { typ = "number", default = 1, sync = true },
	bean    		= { typ = "number", default = 0, sync = true },
	gold    		= { typ = "number", default = 0, sync = true },
	create_time    	= { typ = "number", default = 0, sync = true },
	last_login_time = { typ = "number", default = 0, sync = true },
	ip				= { typ = "string", default = '127.0.0.1', sync = true },
	recharge    	= { typ = "number", default = 0, sync = true },
	room_id	    	= { typ = "number", default = 0, sync = true },
	channel			= { typ = "string", default = '', sync = false},
	daili_1			= { typ = "number", default = 0, sync = true},
	moneyall		= { typ = "number", default = 0, sync = true},
	--expires_time	= { typ = "number", default = 0, sync = true}
}

user_t = class("user_t")
function user_t:ctor()
    local function on_set(obj,key,index,value)
        --skynet.error(">> user_t ", key, index, value)
        -- 同步修改的字段
        send_package(self.fd,
        {
			cmd = NetCmd.S2C_SYNC_USER_DATA,
			key = key,
			index = index,
			value = sync_schema(value),
        })
    end


    if IS_SERVER_MODULE then
		set_schema({
			obj = self,
			schema = userSchema,
			on_set = on_set,
		}) 
    else
		set_schema({
			obj = self,
			schema = userSchema,
		})
    end

    self.fd = nil
    self.account = nil

end

function user_t:get_uid()
    return self.uid
end
